/*
This file is the main source file for XHk.
Copyright (C) <2008>  <Benjamin Carper>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "XHk.h"
#include "Utilities/EventError.h"

static void HK_CALL errorReport(const char* msg, void* object)
{
	String^ netMessage = gcnew String(msg);
	//System::Console::WriteLine(netMessage);
	System::Diagnostics::Debug::WriteLine(netMessage);
	
	// TODO: Append the message the current output file.
}


hkTestEntry* hkUnitTestDatabase;
hkBool HK_CALL hkTestReport(hkBool32 cond, const char* desc, const char* file, int line)
{
	errorReport(desc, 0);
	return true;
}

namespace Havok
{

	void HkBaseSystem::Init()
	{
		hkPoolMemory* memoryManager = new hkPoolMemory();
		hkThreadMemory* threadMemory = new hkThreadMemory(memoryManager, 16);
		hkBaseSystem::init(memoryManager, threadMemory, errorReport);
		memoryManager->removeReference();

		char* stackBuffer;
		{
			int stackSize = 0x100000;
			stackBuffer = hkAllocate<char>(stackSize, HK_MEMORY_CLASS_BASE);
			hkThreadMemory::getInstance().setStackArea( stackBuffer, stackSize );
		}

		hkError::replaceInstance( new Utilities::hkEventError() );
	}
}
